/*
 * @Author       : ShiJunJie
 * @Date         : 2022-04-12 10:19:27
 * @LastEditors  : ShiJunJie
 * @LastEditTime : 2022-04-15 10:19:28
 * @FilePath     : /src/stores/theme.ts
 * @Descripttion : 
 */
import { toggleTheme } from '@zougt/vite-plugin-theme-preprocessor/dist/browser-utils.js'

export type ThemeType = 'theme-default' | 'theme-green'

const ThemeMap = {
  'theme-default': 'theme-default',
  'theme-green': 'theme-green',
}

export const useThemeStore = defineStore('theme', {
  state: () => {
    let theme: ThemeType = ThemeMap[localStorage.getItem("theme-store")] || 'theme-green';
    if (localStorage.getItem("theme-store")) {
      toggleTheme({ scopeName: theme })
    }
    return { theme }
  },
  actions: {
    set(theme: ThemeType) {
      toggleTheme({ scopeName: theme })
      localStorage.setItem("theme-store", `${theme}`);
    },
  },
})
